package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Scenic;
import cn.wolfcode.trip.base.domain.Ticket;
import cn.wolfcode.trip.base.query.ScenicQueryObject;
import cn.wolfcode.trip.base.service.IScenicService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/scenics")
public class ScenicController {
    
    @Autowired
    private IScenicService scenicService;
    
    @GetMapping
    public PageInfo list(ScenicQueryObject qo) {
        if (qo.getHistory()==1){
            scenicService.insertHistory(qo.getKeyword());
        }
        qo.setPageSize(0);
        return scenicService.queryForApp(qo);

    }

    @GetMapping("/hot")
    public List<Scenic> listHot(Integer state) {
        return scenicService.queryForHot(state);
    }

    @GetMapping("/{id}/tickets")
    public Scenic get(@PathVariable Long id) {
        return scenicService.get(id);
    }

    @GetMapping("/tickets/{id}")
    public List<Ticket> getTicket(@PathVariable Long id) {
        return scenicService.getTicket(id);
    }

    @GetMapping("/history")
    public List listAll() {
        return scenicService.listHistory();
    }

}
